package com.example.result

import android.app.Activity
import android.app.Application
import android.content.Context
import android.os.Build
import androidx.annotation.RequiresApi
import com.example.result.crash.CrashHandler
import com.example.result.preference.Config
import com.lly.markdown.MarkdownServer
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class ResultApp : BaseApp() {
}

open class BaseApp : Application() {
    val activities = ArrayList<Activity>()

    @RequiresApi(Build.VERSION_CODES.M)
    override fun attachBaseContext(base: Context?) {
//        TimeProfile.listenerMainLoop()
        TimeProfile.begin(TimeProfile.TOTLE, TimeProfile.APP_BEFORE_ACT, TimeProfile.APPLICATION)
        super.attachBaseContext(base)
//        AppInjector.init(this)
    }

    override fun onCreate() {
        super.onCreate()
        val crashHandler: CrashHandler = CrashHandler.INSTANCE
        crashHandler.init(this)
        TimeProfile.end(TimeProfile.APPLICATION)
        Config.getCrashDir(this)?.absolutePath?.let {
            MarkdownServer.exceptionSavePath = it
            MarkdownServer.setPanic(MarkdownServer.exceptionSavePath)
        }
    }

}